"""author: xueyou
   data: 2020/10/28
   project: ludingji
"""

import random
print("欢迎使用三乐购物系统")
username = input("请输入账号:")
password = input("请输入密码:")
if len(username) < 8:
    print("账号长度不够，请重试")
elif  not password.isalpha():
    print("密码格式不正确")
else:
    pass

input("是否进入购物系统:")

car = [{'name': 'Ferrari LaFerrari', 'price': 20000000},
       {'name': 'Ferrari Enzo', 'price': 15000000},
       {'name': 'Ferrari California', 'price': 3600000},
       {'name': 'Ferrari 488', 'price': 4800000},
       {'name': 'Ferrari FF', 'price': 5000000}]
shopping_cart = {}
money = input("you money")
if money.isdigit():
    user_money = int(money)
    for i,j in enumerate(car,start=1):
        print('car_id:{},car_name:{},money:{}'.format(i,j['name'],j['price']))
    while True:
        num_id_str = input("please enter ID:")
        if num_id_str.isdigit():
            num_id = int(num_id_str)
            if num_id > 0 and num_id <= len(car):
                num_count_str = input("please enter the quantity you want to purchase:")
                if num_count_str.isdigit():
                    num_count = int(num_count_str)
                    num_m = car[num_id - 1]['price']
                    total_car = num_m * num_count
                    if total_car <= user_money:
                        # 1.获取序号对应的商品名称
                        product_name = car[num_id - 1]['name']
                        ret = shopping_cart.get(product_name)  # 去购物车查找对应的商品名称
                        # None
                        if ret:
                            # 获取购物车中原有的数量
                            yysl = shopping_cart[product_name]
                            # 总共的数量
                            shopping_cart[product_name] = yysl + num_id
                            print(shopping_cart)

                        else:
                            # 添加数量
                            shopping_cart[product_name] = num_id
                            print(shopping_cart)
                            #  去购物车进行查询如果有就添加数量 如果没有就添加商品和数量
                            # 输出用户剩余的钱
                        user_money = user_money - total_car
                        print('用户剩余的钱：', user_money)
                    else:
                        print('您的余额不足')
                        break
            else:
                print("看清楚啊，铁子")
        else:
            print("梦想第一步你都能输错?")
else:
    print("输入你的梦啊，铁子")








